import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;


public class BioCategorizer {

	private JFrame frmBiocategorizerByOgi;
	private JTextField txtFilecsv;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private static  String outputFile;
	private int listP=0;
	private JTextField exportedCSV;
	private JTextField textField_6;
	private JTextField textField_7;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					BioCategorizer window = new BioCategorizer();
					window.frmBiocategorizerByOgi.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public BioCategorizer() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */

	private void initialize() {
		frmBiocategorizerByOgi = new JFrame();
		frmBiocategorizerByOgi.setTitle("BioCategorizer by Ogi");
		frmBiocategorizerByOgi.setBounds(100, 100, 852, 615);
		frmBiocategorizerByOgi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JLabel lblNewLabel = new JLabel("Path to the CSV file to load:");

		txtFilecsv = new JTextField();
		txtFilecsv.setText("d:\\biospajz\\arlista_projekt\\Herbahaz_liste_byogi_csv.csv");
		txtFilecsv.setColumns(10);
		final ArrayList<Item> itemList = new ArrayList<Item>();
		final ArrayList<Item> itemListExported = new ArrayList<Item>();
		//final Iterator<Item> iterator= null;
		final JList list = new JList();
		final JTree tree = new JTree();
		final JPanel panel = new JPanel();
		panel.setEnabled(false);
		panel.setBorder(new TitledBorder(null, "Selected item's information", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		final JButton btnGenerate = new JButton("Generate");
		final JButton prev = new JButton();
		final JButton next = new JButton();
		final JLabel lblNull = new JLabel("null");
		btnGenerate.setEnabled(false);
		btnGenerate.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				Random generator = new Random();  
				int num = 0;
			    boolean isIn = true;
			    while (isIn) {
			    	generator.setSeed(System.currentTimeMillis());
				    num = generator.nextInt(900000) + 100000;
			    	isIn = false;
			    	for (int i = 0;i<itemListExported.size()-1;++i) {
			    		if (itemListExported.get(i).getCikkSzam().equals(num+"")) {
			    			isIn = true;
			    			break;
			    		}
			    	}
			    }
			    textField_1.setText(num+"");
			    itemList.get(listP).setCikkSzam(num+"");
			}
		});
		JButton btnLoad = new JButton("Load");
		final JButton loadExported = new JButton("Load");
		loadExported.setEnabled(false);
		btnLoad.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				try {
					if (txtFilecsv.getText().length()>0) {
						System.out.println("aawd");
						loadExported.setEnabled(true);
						File file = new File(txtFilecsv.getText());
						itemList.addAll(CSVParser.parseAndReturnListOfItems(file));
						
						
					} else {
						throw new Exception("No such file.");
					}

					/*for (Object element : itemList)
					    .addElement(element);
					 */
				} catch(Exception e) {
					e.printStackTrace();
				}
			}
		});

		final JButton btnOkExport = new JButton("Ok, Export");
		btnOkExport.setEnabled(false);
		btnOkExport.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
			        PrintWriter pw = null;

			        try {
			            pw = new PrintWriter(BioCategorizer.outputFile);
			            for(int i=0;i<itemList.size();i++) {
							System.out.println(itemList.get(i));
							pw.println(itemList.get(i));
						}
			        } catch (FileNotFoundException e) {
			            e.printStackTrace();
			        } finally {
			            if (pw != null) pw.close();
			        }
			    
				
			}
		});

		

		JLabel lblNewLabel_1 = new JLabel("Cikksz\u00E1m:");

		JLabel lblNewLabel_2 = new JLabel("N\u00E9v:");

		JLabel lblNewLabel_3 = new JLabel("Nett\u00F3 \u00E1r:");

		JLabel lblNewLabel_4 = new JLabel("Brutt\u00F3 \u00E1r:");

		textField_1 = new JTextField();
		textField_1.setEditable(false);
		textField_1.setEnabled(false);
		textField_1.setColumns(10);

		textField_2 = new JTextField();
		textField_2.setEnabled(false);
		textField_2.setColumns(10);

		textField_3 = new JTextField();
		textField_3.setEnabled(false);
		textField_3.setColumns(10);

		textField_4 = new JTextField();
		textField_4.setEnabled(false);
		textField_4.setColumns(10);

		JLabel lblKategoria = new JLabel("Kategoria1:");

		textField_5 = new JTextField();
		textField_5.setEditable(false);
		textField_5.setEnabled(false);
		textField_5.setColumns(10);
		
		textField_6 = new JTextField();
		textField_6.setEnabled(false);
		textField_6.setColumns(10);
		
		JLabel lblTmeg = new JLabel("T\u00F6meg:");
		lblTmeg.setVerticalAlignment(SwingConstants.TOP);
		
		JLabel lblKg = new JLabel("kg");
		
		textField_7 = new JTextField();
		textField_7.setEnabled(false);
		textField_7.setColumns(10);
		
		JLabel lblEgyseg = new JLabel("Egyseg:");
		
		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				itemList.get(listP).setTermekNev(textField_2.getText());
				itemList.get(listP).setNettoAr(textField_3.getText());
				itemList.get(listP).setBruttoAr(textField_4.getText());
				itemList.get(listP).setTomeg(textField_6.getText());
				itemList.get(listP).setEgyseg(textField_7.getText());
				
			}
		});

		
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(23)
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblNewLabel_3)
						.addComponent(lblNewLabel_2)
						.addComponent(lblNewLabel_1)
						.addComponent(lblNewLabel_4)
						.addComponent(lblKategoria)
						.addComponent(lblTmeg, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblEgyseg, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(textField_7, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnSave))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
							.addComponent(btnGenerate))
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_5, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(textField_6, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(lblKg)))
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnGenerate))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_3)
						.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_4)
						.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblKategoria)
						.addComponent(textField_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(8)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblTmeg)
						.addComponent(lblKg))
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_panel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblEgyseg))
							.addContainerGap(14, Short.MAX_VALUE))
						.addGroup(gl_panel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnSave)
							.addContainerGap())))
		);
		panel.setLayout(gl_panel);
		
		
		ImageIcon icon = new ImageIcon("1328615994_Arrow-Left.png");
		prev.setIcon(icon);
		prev.setEnabled(false);
		prev.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				if (listP>0) {
					lblNull.setText(((listP+1)-1)+" of " + itemList.size());
					textField_1.setText(itemList.get(listP-1).getCikkSzam());
					textField_2.setText(itemList.get(listP-1).getTermekNev());
					textField_3.setText(itemList.get(listP-1).getNettoAr());
					textField_4.setText(itemList.get(listP-1).getBruttoAr());
					textField_5.setText(itemList.get(listP-1).getKategoria());
					textField_6.setText(itemList.get(listP-1).getTomeg());
					textField_7.setText(itemList.get(listP-1).getEgyseg());
					listP--;
				}
			}
		});
		
		ImageIcon icon2 = new ImageIcon("1328616005_Arrow-Right.png");
		next.setIcon(icon2);
		next.setEnabled(false);
		next.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				//Iterator<Item> iterator= itemList.iterator();
				if (itemList.size()-1>listP) {
					lblNull.setText((listP+2)+" of " + itemList.size());
					textField_1.setText(itemList.get(listP+1).getCikkSzam());
					textField_2.setText(itemList.get(listP+1).getTermekNev());
					textField_3.setText(itemList.get(listP+1).getNettoAr());
					textField_4.setText(itemList.get(listP+1).getBruttoAr());
					textField_5.setText(itemList.get(listP+1).getKategoria());
					textField_6.setText(itemList.get(listP+1).getTomeg());
					textField_7.setText(itemList.get(listP+1).getEgyseg());
					
					listP++;
				}
			}
		});
		
		JScrollPane scrollPane = new JScrollPane();
		
		JLabel lblPathToThe = new JLabel("Path to the exported CSV file:");
		
		exportedCSV = new JTextField();
		exportedCSV.setText("d:\\\\biospajz\\\\arlista_projekt\\\\UnasShop_biospajz-unas-hu_20120221_teszt.csv");
		exportedCSV.setColumns(10);
		
		
		loadExported.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				try {
					if (txtFilecsv.getText().length()>0) {
						
						File file = new File(exportedCSV.getText());
						BioCategorizer.outputFile = exportedCSV.getText() + "out.csv";
						itemListExported.addAll(CSVParser.parseExportedAndReturnListOfItems(file));
						for (Item item : itemListExported) {
							System.out.println(item);
						}
						tree.setEnabled(true);
						btnOkExport.setEnabled(true);
						textField_1.setEnabled(true);
						textField_2.setEnabled(true);
						textField_3.setEnabled(true);
						textField_4.setEnabled(true);
						textField_5.setEnabled(true);
						textField_6.setEnabled(true);
						textField_7.setEnabled(true);
						
						btnGenerate.setEnabled(true);
						lblNull.setText("1 of " + itemList.size());
						prev.setEnabled(true);
						next.setEnabled(true);
						//list.add(itemList.toArray());
						textField_2.setText(itemList.get(0).getTermekNev());
						textField_3.setText(itemList.get(0).getNettoAr());
						textField_4.setText(itemList.get(0).getBruttoAr());
						textField_6.setText(itemList.get(0).getTomeg());
						textField_7.setText(itemList.get(0).getEgyseg());
						tree.setEnabled(true);
						panel.setEnabled(true);
					} else {
						throw new Exception("No such file.");
					}

					/*for (Object element : itemList)
					    .addElement(element);
					 */
				} catch(Exception e) {
					e.printStackTrace();
				}
			}
		});
		
		JLabel label = new JLabel("1");
		label.setFont(new Font("Tahoma", Font.PLAIN, 20));
		
		JLabel label_1 = new JLabel("2");
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
		
		JLabel label_2 = new JLabel("3");
		label_2.setFont(new Font("Tahoma", Font.PLAIN, 20));
		
		JLabel label_3 = new JLabel("4");
		label_3.setFont(new Font("Tahoma", Font.PLAIN, 20));
		
		

	
		GroupLayout groupLayout = new GroupLayout(frmBiocategorizerByOgi.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(26)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 141, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED, 255, Short.MAX_VALUE))
										.addGroup(groupLayout.createSequentialGroup()
											.addGap(0)
											.addComponent(prev, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
											.addGap(88)
											.addComponent(lblNull)
											.addPreferredGap(ComponentPlacement.RELATED, 196, Short.MAX_VALUE)
											.addComponent(next, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
											.addGap(20))
										.addComponent(lblPathToThe)
										.addGroup(groupLayout.createSequentialGroup()
											.addGap(10)
											.addComponent(exportedCSV, GroupLayout.PREFERRED_SIZE, 205, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(loadExported, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
											.addGap(18)
											.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE))
										.addGroup(groupLayout.createSequentialGroup()
											.addGap(10)
											.addComponent(txtFilecsv, GroupLayout.PREFERRED_SIZE, 205, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(btnLoad)
											.addGap(18)
											.addComponent(label)))
									.addGap(2))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(panel, GroupLayout.PREFERRED_SIZE, 386, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(44)
							.addComponent(list, GroupLayout.PREFERRED_SIZE, 346, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 238, GroupLayout.PREFERRED_SIZE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(36)
							.addComponent(btnOkExport)
							.addGap(33))
						.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(label_3, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE)
							.addGap(67))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(223)
							.addComponent(label_3, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnOkExport))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(34)
							.addComponent(lblNewLabel)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(txtFilecsv, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(btnLoad)
								.addComponent(label))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(lblPathToThe)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(exportedCSV, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(loadExported)
								.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
							.addGap(31)
							.addComponent(list, GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
										.addComponent(prev, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
										.addComponent(next, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(23)
									.addComponent(lblNull)))
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(panel, GroupLayout.PREFERRED_SIZE, 229, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(80)
									.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(43)
							.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE)))
					.addContainerGap())
		);
		
				
				tree.setEnabled(false);
				tree.setVisibleRowCount(40);
				scrollPane.setViewportView(tree);
				tree.setModel(new DefaultTreeModel(
					new DefaultMutableTreeNode("Fokategoriak") {
						{
							DefaultMutableTreeNode node_1;
							DefaultMutableTreeNode node_2;
							DefaultMutableTreeNode node_3;
							node_1 = new DefaultMutableTreeNode("Bio\u00E9lelmiszerek");
								node_1.add(new DefaultMutableTreeNode("Alapanyagok s\u00FCt\u00E9shez"));
								node_1.add(new DefaultMutableTreeNode("B\u00E9bi \u00E9telek, b\u00E9bi italok"));
								node_2 = new DefaultMutableTreeNode("Bef\u0151ttek, konzervek");
									node_2.add(new DefaultMutableTreeNode("Bef\u0151ttek"));
									node_2.add(new DefaultMutableTreeNode("Konzervek"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Cukrok, \u00E9des\u00EDt\u0151k, m\u00E9zek");
									node_2.add(new DefaultMutableTreeNode("Cukrok"));
									node_2.add(new DefaultMutableTreeNode("\u00C9des\u00EDt\u0151k"));
									node_2.add(new DefaultMutableTreeNode("M\u00E9zek"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("\u00C9dess\u00E9gek, s\u00FCtem\u00E9nyek, r\u00E1gcs\u00E1lnival\u00F3k");
									node_2.add(new DefaultMutableTreeNode("Apr\u00F3 \u00E9dess\u00E9gek"));
									node_2.add(new DefaultMutableTreeNode("Csokol\u00E1d\u00E9k"));
									node_2.add(new DefaultMutableTreeNode("Pudingok"));
									node_2.add(new DefaultMutableTreeNode("R\u00E1gcs\u00E1lnival\u00F3"));
								node_1.add(node_2);
								node_1.add(new DefaultMutableTreeNode("Egy\u00E9b bio term\u00E9k"));
								node_2 = new DefaultMutableTreeNode("\u00C9tel\u00EDzes\u00EDt\u0151k");
									node_2.add(new DefaultMutableTreeNode("Ketchup"));
									node_2.add(new DefaultMutableTreeNode("Must\u00E1r"));
									node_2.add(new DefaultMutableTreeNode("Sz\u00F3sz, \u00F6ntet"));
									node_2.add(new DefaultMutableTreeNode("Majon\u00E9z, torma"));
								node_1.add(node_2);
								node_1.add(new DefaultMutableTreeNode("Fagyasztott \u00E9lelmiszerek"));
								node_2 = new DefaultMutableTreeNode("F\u0171szerek, leveskock\u00E1k, z\u00F6lds\u00E9gkr\u00E9mek, el\u0151\u00E9telek");
									node_2.add(new DefaultMutableTreeNode("El\u0151\u00E9telek"));
									node_2.add(new DefaultMutableTreeNode("F\u0171szerek"));
									node_2.add(new DefaultMutableTreeNode("Leveskock\u00E1k \u00E9s porok"));
									node_2.add(new DefaultMutableTreeNode("Kr\u00E9mek"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Gabon\u00E1k, gabonapelyhek, m\u00FCzlik");
									node_2.add(new DefaultMutableTreeNode("Puffasztott szeletek"));
									node_2.add(new DefaultMutableTreeNode("Gabonaf\u00E9l\u00E9k"));
									node_2.add(new DefaultMutableTreeNode("Gy\u00FCm\u00F6lcs- \u00E9s m\u00FCzliszeletek"));
									node_2.add(new DefaultMutableTreeNode("M\u00FCzlik"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("H\u00FAs \u00E9s h\u00FAsk\u00E9sz\u00EDtm\u00E9nyek");
									node_2.add(new DefaultMutableTreeNode("Mangalica"));
									node_2.add(new DefaultMutableTreeNode("Sz\u00FCrkemarha"));
									node_2.add(new DefaultMutableTreeNode("Sz\u00FCrkemarha n\u00F6vend\u00E9k"));
									node_2.add(new DefaultMutableTreeNode("Sz\u00FCrkemarha borj\u00FA"));
									node_2.add(new DefaultMutableTreeNode("Racka juh"));
									node_2.add(new DefaultMutableTreeNode("Tejes b\u00E1r\u00E1ny"));
									node_2.add(new DefaultMutableTreeNode("Baromfi"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("K\u00E1v\u00E9, kaka\u00F3, karob");
									node_2.add(new DefaultMutableTreeNode("Kaka\u00F3"));
									node_2.add(new DefaultMutableTreeNode("K\u00E1v\u00E9"));
									node_2.add(new DefaultMutableTreeNode("Karob"));
								node_1.add(node_2);
								node_1.add(new DefaultMutableTreeNode("Keny\u00E9r, p\u00E9k\u00E1r\u00FA\t"));
								node_2 = new DefaultMutableTreeNode("K\u00E9sz \u00E9s f\u00E9lk\u00E9sz term\u00E9kek");
									node_3 = new DefaultMutableTreeNode("K\u00E9sz \u00E9telek");
										node_3.add(new DefaultMutableTreeNode("Levesek"));
										node_3.add(new DefaultMutableTreeNode("F\u0151zel\u00E9kek"));
										node_3.add(new DefaultMutableTreeNode("Egyt\u00E1l\u00E9telek"));
										node_3.add(new DefaultMutableTreeNode("Gabona fas\u00EDrtok"));
										node_3.add(new DefaultMutableTreeNode("Gabona p\u00F6rk\u00F6ltek"));
										node_3.add(new DefaultMutableTreeNode("Halas \u00E9telek"));
										node_3.add(new DefaultMutableTreeNode("K\u00F6rtek"));
										node_3.add(new DefaultMutableTreeNode("\u00C9dess\u00E9gek"));
									node_2.add(node_3);
									node_2.add(new DefaultMutableTreeNode("F\u00E9lk\u00E9sz"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Lisztek, kieg\u00E9sz\u00EDt\u0151k");
									node_2.add(new DefaultMutableTreeNode("Keny\u00E9r kever\u00E9kek"));
								node_1.add(node_2);
								node_1.add(new DefaultMutableTreeNode("M\u00E9zek, lekv\u00E1rok, gy\u00FCm\u00F6lcsp\u00FCr\u00E9k"));
								node_1.add(new DefaultMutableTreeNode("N\u00F6v\u00E9nyi h\u00FAsp\u00F3tl\u00F3k"));
								node_2 = new DefaultMutableTreeNode("Olajos magvak, aszalt gy\u00FCm\u00F6lcs\u00F6k, kr\u00E9mek");
									node_2.add(new DefaultMutableTreeNode("Aszalt gy\u00FCm\u00F6lcs\u00F6k"));
									node_2.add(new DefaultMutableTreeNode("Kr\u00E9mek"));
									node_2.add(new DefaultMutableTreeNode("Olajos magvak"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Te\u00E1k");
									node_2.add(new DefaultMutableTreeNode("Chai"));
									node_2.add(new DefaultMutableTreeNode("Herba"));
									node_2.add(new DefaultMutableTreeNode("F\u0171szeres"));
									node_2.add(new DefaultMutableTreeNode("F\u0171szeres sz\u00E1las"));
									node_2.add(new DefaultMutableTreeNode("N\u0151i, f\u00E9rfi"));
									node_2.add(new DefaultMutableTreeNode("Z\u00F6ld"));
									node_2.add(new DefaultMutableTreeNode("Egy\u00E9b"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("T\u00E9szt\u00E1k, rizsek");
									node_3 = new DefaultMutableTreeNode("T\u00E9szt\u00E1k");
										node_3.add(new DefaultMutableTreeNode("Durum feh\u00E9r t\u00E9szt\u00E1k"));
										node_3.add(new DefaultMutableTreeNode("K\u00FCl\u00F6nleges t\u00E9szt\u00E1k"));
										node_3.add(new DefaultMutableTreeNode("Teljes ki\u0151rl\u00E9s\u0171 t\u00E9szt\u00E1k"));
									node_2.add(node_3);
									node_2.add(new DefaultMutableTreeNode("Rizsek"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Tejterm\u00E9kek");
									node_2.add(new DefaultMutableTreeNode("Tej"));
									node_2.add(new DefaultMutableTreeNode("Tejf\u00F6l"));
									node_2.add(new DefaultMutableTreeNode("T\u00FAr\u00F3"));
									node_2.add(new DefaultMutableTreeNode("Sajt"));
									node_2.add(new DefaultMutableTreeNode("Kr\u00E9mek"));
									node_2.add(new DefaultMutableTreeNode("Egy\u00E9b"));
								node_1.add(node_2);
								node_1.add(new DefaultMutableTreeNode("Tejhelyettes\u00EDt\u0151 term\u00E9kek"));
								node_2 = new DefaultMutableTreeNode("Z\u00F6lds\u00E9g \u00E9s gy\u00FCm\u00F6lcslevek");
									node_2.add(new DefaultMutableTreeNode("Z\u00F6lds\u00E9g l\u00E9"));
									node_2.add(new DefaultMutableTreeNode("Gy\u00FCm\u00F6lcs l\u00E9"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Z\u00F6lds\u00E9g, gy\u00FCm\u00F6lcs, toj\u00E1s");
									node_2.add(new DefaultMutableTreeNode("Z\u00F6lds\u00E9g"));
									node_2.add(new DefaultMutableTreeNode("Gy\u00FCm\u00F6lcs"));
									node_2.add(new DefaultMutableTreeNode("Toj\u00E1s"));
								node_1.add(node_2);
								node_2 = new DefaultMutableTreeNode("Zs\u00EDrok, olajok, ecetek");
									node_2.add(new DefaultMutableTreeNode("Olajok"));
									node_2.add(new DefaultMutableTreeNode("Zs\u00EDrok"));
									node_2.add(new DefaultMutableTreeNode("Ecetek"));
								node_1.add(node_2);
							add(node_1);
							add(new DefaultMutableTreeNode("Gy\u00F3gyn\u00F6v\u00E9nyek, gy\u00F3gyte\u00E1k"));
							add(new DefaultMutableTreeNode("\u00C9trend-kieg\u00E9sz\u00EDt\u0151k, vitaminok"));
							add(new DefaultMutableTreeNode("Bi\u00F3 \u00E9s nat\u00FArtiszt\u00EDt\u00F3szerek"));
							add(new DefaultMutableTreeNode("Aromater\u00E1pi\u00E1s term\u00E9kek"));
							add(new DefaultMutableTreeNode("K\u00F6nyvek, \u00FAjs\u00E1gok"));
							add(new DefaultMutableTreeNode("Reform \u00E9s nat\u00FAr\u00E9lelmiszerek"));
							node_1 = new DefaultMutableTreeNode("Speci\u00E1lis di\u00E9t\u00E1khoz sz\u00FCks\u00E9ges");
								node_1.add(new DefaultMutableTreeNode("Glut\u00E9nmentes"));
								node_1.add(new DefaultMutableTreeNode("Tejmentes"));
								node_1.add(new DefaultMutableTreeNode("Gerson di\u00E9ta"));
								node_1.add(new DefaultMutableTreeNode("SCD, Paleolita, GAPS di\u00E9ta"));
								node_1.add(new DefaultMutableTreeNode("Anti-candida di\u00E9ta"));
								node_1.add(new DefaultMutableTreeNode("Diabetikus alapanyagok"));
								node_1.add(new DefaultMutableTreeNode("Toj\u00E1smentes"));
								node_1.add(new DefaultMutableTreeNode("Lakt\u00F3zmentes"));
							add(node_1);
							add(new DefaultMutableTreeNode("Bio \u00E9s nat\u00FArkozmetikumok"));
							add(new DefaultMutableTreeNode("\u00C1sv\u00E1nyv\u00EDz, gy\u00F3gyv\u00EDz"));
						}
					}
				));
				tree.addTreeSelectionListener(new TreeSelectionListener() {
					public void valueChanged(TreeSelectionEvent e) {
						DefaultMutableTreeNode node = (DefaultMutableTreeNode)
								tree.getLastSelectedPathComponent();
						TreePath currentSelection = tree.getSelectionPath();
						
						/* if nothing is selected */ 
						if (node == null) return;
						String path = currentSelection.getPathComponent(1).toString();
						for (int i=2;i<currentSelection.getPathCount();++i) {
							path=path+"|"+ currentSelection.getPathComponent(i).toString();
						}
						textField_5.setText(path);
						itemList.get(listP).setKategoria(path);
						
						/* retrieve the node that was selected */ 
						// Object nodeInfo = node.getUserObject();
						System.out.println(path);
					}
				});
		frmBiocategorizerByOgi.getContentPane().setLayout(groupLayout);
	}
}

//TreePath currentSelection = tree.getSelectionPath();
